/**
 * 
 */
package com.jdy.haoduoai.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jdy.haoduoai.Constant;
import com.jdy.haoduoai.activity.SplashActivity;
import com.ycsj.goldmedalnewconcept.R;

/**
 * @author zp 2016-6-3 下午5:35:47
 */
public class WelcomePageFragment extends Fragment {
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.welcome_page_layout, container, false);

    int imgSrc = getArguments().getInt("src");

    ImageView img = (ImageView) v.findViewById(R.id.welcome_page_img);

    img.setImageResource(imgSrc);

    if (imgSrc == R.drawable.welcome_5) {
      img.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
          SharedPreferences prefs = getActivity().getSharedPreferences(
              Constant.WELCOME_PAGE, Context.MODE_PRIVATE);
          prefs.edit().putBoolean(Constant.HAS_ILLUSTRATED, true).apply();

          Intent i = new Intent(getActivity(), SplashActivity.class);
          i.putExtra("comefromwelcomepage", 1);
          startActivity(i);
        }
      });
    }

    return v;
  }

  public static WelcomePageFragment newInstance(int srcId) {

    WelcomePageFragment f = new WelcomePageFragment();

    Bundle b = new Bundle();

    b.putInt("src", srcId);

    f.setArguments(b);

    return f;
  }
}
